package com.example.myapplication;

import java.util.List;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
public class WarAdapter extends ArrayAdapter<WarRecord> {


private int resourceId;
    public WarAdapter( Context context,  int textViewResourceId,  List<WarRecord> objects) {
        super(context, textViewResourceId, objects);
        resourceId=textViewResourceId;
    }

     @Override
    public View getView(final int position , View convertView, ViewGroup parent){
        WarRecord war = getItem(position);
      ViewHolder holder;
        if (convertView==null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(getContext()).inflate( resourceId, null);
            holder.warName = (TextView) convertView.findViewById(R.id.war_name);
            convertView.setTag(holder);
        }
        else {
            holder=(ViewHolder)convertView.getTag();
        }
        holder.warName.setText(war.getName());
        if(war.getStatus()==0)
        {
            holder.warName.setTextColor(Color.BLACK);
        }else
         holder.warName.setTextColor(Color.GREEN);
         return convertView;
     }
    static class ViewHolder {
        TextView warName;
    }
}
